<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}

require_once('calendar/classes/tc_calendar.php');
$_SESSION['action'] = "my_meeting_sending";
?>
<?php 


if(!isset($_REQUEST['page'])){

$list["a.Tile"]="DESC";
$list["a.Timecreate"]="DESC";
$list["a.IDApproveDoc"]="DESC";
//$str=$_SESSION['sortn'];
//if($str==''){
$str="a.Timecreate";
$_SESSION['sortn']=$str;
//}
$_SESSION['sort']=$list;	
}else{
	$str=$_SESSION['sortn'];
	$list=$_SESSION['sort'];
}
    if(array_key_exists("page",$_GET))
        $page  = $_GET['page'];
    else
        $page = 1;

    $abc = ($page-1)*10;
    
    if (isset($_REQUEST['search'])){
    	$tile=$_REQUEST['titleSearch'];
    	$fromdate=$_REQUEST['date1'];
    	$todate=$_REQUEST['date2'];
    	$search=$_REQUEST['search'];
    	
    	$sql="SELECT a.IDApproveDoc,e.FullName,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,DATE_FORMAT(a.TimeApprove, '%Y-%m-%d') as DateApprove  
								FROM approvedoc a,employee e 
								WHERE a.IDEmployee=e.IDEmployee AND a.IDEmployee='$id_employee' AND a.IDStatus=2 AND a.IDTypeDoc = 11 
									AND a.Tile LIKE '%$tile%' AND a.Timecreate>'".$fromdate." 00:00:00' AND a.Timecreate<'".$todate." 23:59:59'";
    	$query= mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
    	$number_of_page = ceil ( mysql_num_rows( $query ) / $rows_per_page ); 
    }
    else {
    	$tile="";
    	$fromdate=date("Y-m-d"); 
    	$todate=date("Y-m-d");
    	
    	$sql="SELECT a.IDApproveDoc,e.FullName,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,DATE_FORMAT(a.TimeApprove, '%Y-%m-%d') as DateApprove  
								FROM approvedoc a,employee e 
								WHERE a.IDEmployee=e.IDEmployee AND a.IDEmployee='$id_employee' AND a.IDStatus=2 AND a.IDTypeDoc = 11 ";
    	$query= mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
    	$number_of_page = ceil ( mysql_num_rows( $query ) / $rows_per_page ); 
    }
    if($page>$number_of_page && $page!=1)
    	$page=$number_of_page;
?>

<script type="text/javascript">
function sort(page,str,co,search,tile,from,to)
{
	

	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
												var body = document.getElementById('content');
												body.setAttribute('style','opacity:.5; position:relative;cursor: wait;  ');
												
												var d=document.createElement('div');
												d.setAttribute('style','display: block;visibility: visible; position: absolute;  z-index: 999; top: 0px; left: 0px; width: 105%; height: 105%; text-align: center;  filter: alpha(opacity=5); opacity: 0.5; ');
												
												var image=document.createElement('img');
												image.setAttribute('src','images/loading1.gif');
												image.setAttribute('style','position:absolute; left:0px; top:0px; right:0; bottom:0; margin:auto');
												
												d.appendChild(image);
												
											    body.appendChild(d);	
											    
											  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											    	document.getElementById("content").innerHTML=xmlhttp.responseText;
											    	document.getElementById('content').setAttribute('style','opacity:1; position:relative;');
											  }
									  }
	xmlhttp.open("GET","ajax/list/sort_my_meeting.php?page="+page+"&str="+str+"&co="+co+"&search="+encodeURI(search)+"&titleSearch="+tile+"&date1="+from+"&date2="+to,true);
	xmlhttp.send();
}

</script>
<style>
<!--
* {margin:0;}
-->
</style>
<div class="title"></div>
                    <div class="content_code">
						<div class="approval-right">
							<form action="mydocument.php" method="get">
							<table width="100%" >
								<tr>
									<td>
										<div class="title_content"><?=$l_my_document ?> &rarr; <?=$l_my_meetingDoc ?></div>
											
											<input type="hidden" name="content" value="list-mydocument-meeting-sending-content" />
											<table border="1" bordercolor="#C5D1E8" cellpadding="4"  style="border-collapse:collapse">
												<tr height="40">
												<td align="center" style="vertical-align:middle;width: 120px"><?=$l_created_date?></td>
												<td align="center" style="height:24px;">
												<?php
												  $myCalendar1 = new tc_calendar("date1", true);
												  $myCalendar1->setIcon("calendar/images/iconCalendar.gif");
												  $d=split('-',$fromdate,3);
												 
												  $myCalendar1->setDate($d[2],$d[1],$d[0]);
												  $myCalendar1->setPath("calendar/");
												  $myCalendar1->setYearInterval(2010, 2015);
												  $myCalendar1->dateAllow('2010-01-01', '2015-12-31');
												  //$myCalendar1->setHeight(350);
												  //$myCalendar1->autoSubmit(true, "form1");
												  //$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
												  $myCalendar1->setOnChange("myChanged('test')");
												  //$myCalendar->rtl = true;
												  $myCalendar1->writeScript();
							
												  //echo $myCalendar1->getDate();
												  
												  ?>
												</td >
												
												  <td align="center" style="height:24px;">
												  <?php
												  $myCalendar2 = new tc_calendar("date2", true);
												  $myCalendar2->setIcon("calendar/images/iconCalendar.gif");
												  $d=split('-',$todate,3);
												 
												  $myCalendar2->setDate($d[2],$d[1],$d[0]);
												  $myCalendar2->setPath("calendar/");
												  $myCalendar2->setYearInterval(2010, 2015);
												  $myCalendar2->dateAllow('2010-01-01', '2015-12-31');
												  //$myCalendar1->setHeight(350);
												  //$myCalendar1->autoSubmit(true, "form1");
												  //$myCalendar1->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
												  $myCalendar2->setOnChange("myChanged('test')");
												  //$myCalendar->rtl = true;
												  $myCalendar2->writeScript();
												  
												  ?>	
                   							  	<!--  >input type="hidden" name="totime" value="<?php echo $myCalendar2->getDate();?>" />
                   							  	<input type="hidden" name="fromtime" value="<?php echo $myCalendar1->getDate();?>" /-->
																
												</td>												
												</tr>
												
												<tr height="40">
												<td align="center" style="vertical-align:middle"><?=$l_title?> </td>
												<td colspan="2" style="padding-left: 3px;padding-right: 3px;">
													<input type="text" name="titleSearch" value="<?=$tile?>" style="width:600px;height:20px;" /></td>
												</tr>
											</table>	
												
																	
												
										</td>
								</tr>
								<tr>
									<td colspan="2" align="left">
										<table width="70%">
										<tr><td align="center">
											<input style="margin:12px 5px 0 0; font-size: 12px;" type="submit" value="<?=$l_search?>" class="btn_choose" name="search" />
											<input style="margin:12px 5px 0 0; font-size: 12px;" type="submit" name="all" value="<?=$l_all?>" class="btn_choose" />
										</td></tr></table>
									</td>
								
								</tr>
								<?php 
											    	$tile=$_REQUEST['titleSearch'];
											    	$fromdate=$_REQUEST['date1'];
											    	$todate=$_REQUEST['date2'];
											    	$search=$_REQUEST['search'];
													//page,str,co,search,tile,from,to,IdSend)
								?>
								
								<tr>
									<td>										
										<div style=" margin-top:30px" >
											<div style="position:relative; padding-bottom: 5px;">
												<input style="margin:12px 5px 0 0; font-size: 12px;" type="submit" name="updateMyApp" value="<?=$l_delete?>" class="btnupbg btnupload"  />
											</div>
										<div id='content'>
											<table width="100%" class="table_th" style="height:22px;" cellspacing="0">
												
												<tr class="trtit" style="background-color:#EEE;">
													<td width="3%"></td>
													<td width="3%"><?=$l_no?></td>
													<!--td width="10%"><a onclick="sort(<?=$page?>,'a.IDApproveDoc','1','<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')">ID</a></td-->
										            <td width="15%"><?=$l_document_form?></td>
										            <td width="30%"><a onclick="sort(<?=$page?>,'a.Tile','1','<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')"><?=$l_title?></a></td>
										 
										            <td width="10%"><a onclick="sort(<?=$page?>,'a.Timecreate','1','<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')"><?=$l_created_date?></a></td>
										 
										            
										        </tr>
												
												
												
												<?php
												
											    $i = 0; 
											    while ($row=mysql_fetch_array($query)){
											    	if ( $i >= $page_start  ) 
													{	
												    	if($row[IDTypeDoc]==11)$document = $l_meeting_document;
													    
												    
												?>
													<tr bgcolor="#ffffff" class="highlighter">
														<td><input type="checkbox" name="xoa[]" value="<?=$row['IDApproveDoc']?>" /></td>
														<td width="3%" align="center"><?=($i+1)?></td>
														<!--td ><a href='mydocument.php?id=<?=$row['IDApproveDoc']?>&type=<?=$row['IDTypeDoc']?>&page=<?=$page?>'><?php echo $row['IDApproveDoc'];?></a></td-->
														<td ><div  align="left" ><?php echo $document;?></div></td>
														<td ><div  align="left" ><a href='mydocument&<?=$row['IDApproveDoc']?>&<?=$row['IDTypeDoc']?>&<?=$page?>'><?=$row['Tile']?></a></div></td>
														<td ><?=$row['Timecreate']?></td>
														
														
													</tr>
												<?php 	}
												
													$i++; 
													
													if ($i >= $page_end) 
													{ 
													break; 
													} 
												}
												
													
												?>
											
											<tr>
													<td colspan="5" class="bt_td_main">
													
													<span style="background:#fff; padding:1px; display: inline-block;">
														
														<?php if ( $number_of_page > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page)
																$p=$number_of_page-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="sort(1,'<?=$str?>',0,'<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="sort(<?=($page-1)?>,'<?=$str?>',0,'<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')" ><span class='button_next'><?php echo "<<";?></span> </a>
															<?php  }
															else{
																echo "<span class='button_next'><<<</span>"; 
																echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next'><b>".$i."</b></span>"; 
																		}else{
																		?>
																			<a onclick="sort(<?=$i?>,'<?=$str?>',0,'<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')" ><span class="button_next" style="color: #508e21;">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page){ ?>
																	<a onclick="sort(<?=($page+1)?>,'<?=$str?>',0,'<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="sort(<?=($number_of_page)?>,'<?=$str?>',0,'<?=$search?>','<?=$tile?>','<?=$fromdate?>','<?=$todate?>')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	echo "<span class='button_next'>>></span> ";
																	echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
																												
													</span>
													</td>
												</tr>
											</table>
											</div>
										</div>
									</td>
								</tr>
							</table>
							</form>	
						</div>
					</div>